<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>GSAP SplitText Official Style Demo</title>
    <style>
        body {
            font-family: 'Avenir', sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            margin: 0;
            color: #2c3e50;
        }

        .container {
            text-align: center;
            max-width: 800px;
            padding: 2rem;
        }

        .split-headline {
            font-size: 3.5rem;
            font-weight: 700;
            margin-bottom: 2rem;
            line-height: 1.2;
        }

        .split-paragraph {
            font-size: 1.4rem;
            line-height: 1.6;
            margin-bottom: 2rem;
            opacity: 0.8;
        }

        .btn {
            display: inline-block;
            padding: 1rem 2.5rem;
            background: #3498db;
            color: white;
            font-size: 1rem;
            font-weight: 600;
            border: none;
            border-radius: 50px;
            cursor: pointer;
            transition: all 0.3s ease;
            box-shadow: 0 4px 15px rgba(52, 152, 219, 0.3);
        }

        .btn:hover {
            background: #2980b9;
            transform: translateY(-2px);
            box-shadow: 0 6px 20px rgba(52, 152, 219, 0.4);
        }

        .char, .word {
            display: inline-block;
            position: relative;
        }

        .line {
            display: block;
            overflow: hidden;
        }
    </style>
</head>
<body>
<div class="container">
    <h1 class="split-headline">Create beautiful text animations with SplitText</h1>
    <p class="split-paragraph">This official approach provides cleaner code and better performance. Each word and character can be animated independently.</p>
    <button class="btn" id="replay">Replay Animation</button>
</div>

<!-- 无需手动注册，可直接使用 -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.11.4/gsap.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/gsap@3.13.0/dist/SplitText.min.js"></script>
<script>
    document.addEventListener('DOMContentLoaded', () => {
        // 使用官方推荐的create方法
        const headline = SplitText.create(".split-headline", {
            type: "words,chars",
            linesClass: "line",
            onSplit(self) {
                gsap.set(self.chars, {
                    y: 30,
                    opacity: 0
                });
            }
        });

        const paragraph = SplitText.create(".split-paragraph", {
            type: "chars",
            onSplit(self) {
                gsap.set(self.chars, {
                    y: 20,
                    opacity: 0
                });
            }
        });

        // 创建主时间轴
        const masterTL = gsap.timeline();

        // 添加动画序列
        masterTL
            .to(headline.chars, {
                duration: 0.8,
                y: 0,
                opacity: 1,
                stagger: 0.03,
                ease: "back.out(1.7)"
            })
            .to(paragraph.chars, {
                duration: 0.5,
                y: 0,
                opacity: 1,
                stagger: 0.01,
                ease: "power2.out"
            }, "-=0.3")
            .to(".btn", {
                duration: 0.8,
                y: 0,
                opacity: 1,
                ease: "elastic.out(1, 0.5)"
            }, "-=0.2");

        // 初始隐藏按钮
        gsap.set(".btn", { opacity: 0, y: 10 });

        // 重新播放动画
        document.getElementById("replay").addEventListener("click", () => {
            masterTL.restart();
        });
    });
</script>
</body>
</html>